package com.config;

import com.Utils.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new JWTInterceptor())
//                .addPathPatterns("/student/**")
//                .excludePathPatterns("/student/findaccount")//查询账号
//                .excludePathPatterns("/student/register")//注册
//                .excludePathPatterns("/student/login")//登录/bk/add
        ;

        registry.addInterceptor(new JWTInterceptor());
//                .addPathPatterns("/teacher/**")
//                .excludePathPatterns("/teacher/findaccount")//查询账号
//                .excludePathPatterns("/teacher/register")//注册
//                .excludePathPatterns("/teacher/login");//登录
        registry.addInterceptor(new JWTInterceptor());
//                .addPathPatterns("/liaotian/**")//登录
//                .excludePathPatterns("/liaotian/select/lishi");//登录
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        File basePath = new File("src/main/resources/static/Headshot");
        String Path = basePath.getAbsolutePath() + File.separator;
        //文件磁盘图片url 映射//配置server虚拟路径，handler为前台访问的目录，locations为files相对应的本地路径
        registry.addResourceHandler("/api/HeadShot/**")
        .addResourceLocations("file:D:\\java\\repaix\\src\\main\\resources\\static\\Headshot\\");
//                 WebMvcConfigurer.super.addResourceHandlers(registry);
        registry.addResourceHandler("/api/UserImages/**")
                .addResourceLocations("file:D:\\java\\repaix\\src\\main\\resources\\static\\UserImages\\");

    }
}


